﻿using System;
using System.Runtime.InteropServices;

namespace Ics.NuttxSharp
{
    public class MQueue
    {
        public struct mq_attr
        {
            public long mq_maxmsg;    /* Max number of messages in queue */
            public long mq_msgsize;   /* Max message size */
            public long mq_flags;     /* Queue flags */
            public long mq_curmsgs;   /* Number of messages currently in queue */
        };

        [DllImport("*")]
        public static extern unsafe IntPtr ics_nuttx_mq_open(string name, int oflag, int mode, mq_attr* attr);
        [DllImport("*")]
        public static extern unsafe int ics_nuttx_mq_close(IntPtr mqdes);
        [DllImport("*")]
        public static extern unsafe int ics_nuttx_mq_send(IntPtr mqdes, byte* msg_ptr, ulong msg_len, uint msg_prio);
        [DllImport("*")]
        public static extern unsafe int ics_nuttx_mq_timedsend(IntPtr mqdes, byte* msg_ptr, ulong msg_len, uint msg_prio, ref timespec abs_timeout);
        [DllImport("*")]
        public static extern unsafe long ics_nuttx_mq_receive(IntPtr mqdes, byte* msg_ptr, ulong msg_len, uint* msg_prio);
        [DllImport("*")]
        public static extern unsafe long ics_nuttx_mq_timedreceive(IntPtr mqdes, byte* msg_ptr, ulong msg_len, uint* msg_prio, ref timespec abs_timeout);

        [DllImport("*")]
        public static extern unsafe int ics_nuttx_mq_unlink(string name);

        //mq_notify
        //[DllImport("*")]
        //public static extern unsafe int ics_nuttx_mq_notify(IntPtr mqdes, sigevent* notification);
    }
}
